﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DoAnWeb.DAO;
using DoAnWeb.DTO;
using DoAnWeb.BUS;

namespace DoAnWeb
{
    public partial class ProductByCat : System.Web.UI.Page
    {
        TinKhuyenMaiBUS BUS = new TinKhuyenMaiBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["CatID"] == null)
                {
                    Response.Redirect("~/Default.aspx");
                    //dlDSSanPham.DataSource = BUS.GetList();
                    //dlDSSanPham.DataBind();
                }
                else
                {
                    int CatID = int.Parse(Request.QueryString["CatID"].ToString());
                    dlDSSanPham.DataSource = BUS.GetList_ForKind(CatID);
                    dlDSSanPham.DataBind();
                }
            }
        }

        protected string SoLuotThamGia(int _MaTinKhuyenMai)
        {
            int SoLuot = new TinKhuyenMaiBUS().CountNumberSelled(_MaTinKhuyenMai);
            if (SoLuot <= 0)
                return "Hãy là người đầu tiên.";
            else
                return SoLuot.ToString() + " lượt.";
        }

        protected bool TinhTrang(int _MaTinKhuyenMai)
        {
            int SoLuongConLai = new TinKhuyenMaiBUS().CountNumberRemain(_MaTinKhuyenMai);
            if (SoLuongConLai <= 0)
                return false;
            else
                return true;
        }
    }
}